/*
 * Wantmore - Service Delivery Platform.
 *
 * $Id: PhotoAlbumFormController.java 60 2010-10-13 07:26:24Z alexey.batyuta@gmail.com $
 *
 * Copyright 2010 by Sunbay Software Crimea Ltd.
 * All rights reserved
 */
package ua.crimea.bat.ss.forms;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import ua.crimea.bat.ss.model.beans.Album;
import ua.crimea.bat.ss.model.beans.Image;
import ua.crimea.bat.ss.services.PhotoAlbumsService;

import java.util.List;

/**
 * User: bat
 * Date: Mar 26, 2010
 * Time: 9:18:30 AM
 */
@Controller("photoAlbumFormController")
public class PhotoAlbumFormController {
    public PhotoAlbumFormController() {
    }

    @Autowired
    public PhotoAlbumFormController(PhotoAlbumsService photoAlbumsService) {
        this.photoAlbumsService = photoAlbumsService;
    }

    protected PhotoAlbumsService photoAlbumsService;


    public void setPhotoAlbumsService(PhotoAlbumsService photoAlbumsService) {
        this.photoAlbumsService = photoAlbumsService;
    }

    public PhotoAlbumsService getPhotoAlbumsService() {
        return photoAlbumsService;
    }

    @InitBinder
    public void setAllowedFields(WebDataBinder dataBinder) {
        dataBinder.setDisallowedFields("id");
    }

    @RequestMapping("/")
    public String welcomeHandler() {
        return "welcome";
    }

    @RequestMapping("/albums/{albumId}")
    public ModelAndView ownerHandler(@PathVariable("albumId") int albumId) {
        ModelAndView modelAndView = new ModelAndView("albums/show");
        final Album album = photoAlbumsService.loadAlbum(albumId);
        final List<Image> images = album.getImages();
        modelAndView.addObject(album);
        modelAndView.addObject(images);
        return modelAndView;
    }
}
